﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using UCOLOR.Helpers;
using UCOLOR.Model;
using UColor.WPF;
namespace UCOLOR.View
{
    /// <summary>
    /// HomeView.xaml 的交互逻辑
    /// </summary>
    public partial class TemplateListView : UCModule 
    {
        public TemplateListView()
        {
            InitializeComponent();
        }
        

        public TemplateListView(string product_no,bool UseWhere = false)
        {
            InitializeComponent();
            
            ShowTemplateDataView(product_no,UseWhere);
           
        }


        public IList<Product> data
        {
            get;
            set;
        }

        public IList<SalesTemplate> salesTemplate
        {
            get;
            set;
        }

        public void ShowPartDataView(IList<SalesTemplate> list)
        {
            this.salesTemplate = list;
            this.DirList.ItemsSource = list;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="template_type"></param>
        public void ShowTemplateDataView(string template_type,bool UseWhere = false)
        {
            this.salesTemplate = DataHelper.GetSalesTemplate(template_type,UseWhere);;
            this.DirList.ItemsSource = salesTemplate;
        }
       

        public void ShowView()
        {
           // ProductView view = new ProductView(1);
           // view.DirList.ItemsSource = data;
        }

        public void ShowView(int id)
        {
           // ProductView view = new ProductView(id);
          //  view.DirList.ItemsSource = data;
        }

        private void Tile_Click(object sender, EventArgs e)
        {

           string catalog_no = ((UCOLOR.Model.SalesTemplate)(((DevExpress.Xpf.LayoutControl.Tile)sender).Content)).file_name;

          // ProductView view = new ProductView(catalog_no);
          //  this.ParentModulePage.OpenModule(view);
          //  view.ShowProduct(1);
        }


        private void Tile_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (e.ClickCount == 2)
            {
                //(this.DataContext as ProductView).ModalDialog.LayoutUpdated += delegate
                //{
                //    (this.DataContext as ProductView).ModalDialog.Margin = new Thickness(
                //            Application.Current.MainWindow.ActualWidth-100,
                //            Application.Current.MainWindow.ActualWidth-100,
                //            0,
                //            0);
                //};
                //(this.DataContext as ProductView).ModalDialog.IsOpen = true;
                //(this.DataContext as ProductView).ModalDialog.Placement = System.Windows.Controls.Primitives.PlacementMode.AbsolutePoint;
                //UCOLOR.APP.FlashPlayer player = new APP.FlashPlayer();
                //player.Source = "create_a_map.swf";

                //(this.DataContext as ProductView).FlashPlay.Children.Add(player);
                //player.SetValue(Grid.ColumnProperty, 0);

                //UCOLOR.Model.SalesTemplate template = ((UCOLOR.Model.SalesTemplate)(((DevExpress.Xpf.LayoutControl.Tile)sender).Content));

               // TemplatePlayView view = new TemplatePlayView(template);
               //// (this.DataContext as ProductView).FlashPlay.Children.Add(view);
               // view.Margin = new Thickness(5, 5, 5, 5);
               // view.HorizontalAlignment = HorizontalAlignment.Stretch;
               // view.VerticalAlignment = VerticalAlignment.Stretch;
               // view.SetValue(Grid.ColumnProperty, 0);

                UColor.Modules.SearchResultViewer view = new UColor.Modules.SearchResultViewer(salesTemplate);
                view.ParentModulePage = this.ParentModulePage;
                ParentModulePage.OpenModule(view);
            }
        }
    }
}
